package com.caipiao.lottery.controller;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.enums.OutPlatformTypeEnum;
import org.jeecg.modules.api.vo.OutPlatformUserVo;
import org.jeecg.modules.sdqj.service.ITOutPlatformUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 服务化 system模块 给外部系统提供接口请求类
 *
 * @author: jeecg-boot
 */
@Slf4j
@RestController
@RequestMapping("/out-api/outplatform")
public class OutPlatformUserController {
    @Autowired
    private ITOutPlatformUserService outPlatformUserService;

    /**
     * 外部接口，根据临时token获取用户信息
     *
     * @param platformId 第三方系统的ID，取值： {@link OutPlatformTypeEnum#id}
     * @param sign       签名，规则：md5(secretKey+platformId+tempToken)
     * @param tempToken  临时token
     * @return 对应的登录账号信息返回 org.jeecg.common.api.vo.Result<java.lang.String>
     * @description 第三方根据临时token获取用户信息对应的外部平台的账号信息
     * @date 2025/4/25 12:01
     */
    @GetMapping("/userInfoByTempToken")
    public Result<OutPlatformUserVo> userInfoByTempToken(
            @RequestParam(value = "platformId") String platformId,
            @RequestParam("sign") String sign,
            @RequestParam("tempToken") String tempToken
    ) {
        if (!OutPlatformTypeEnum.containsId(platformId)) {
            return Result.error("平台id不存在");
        }
        return outPlatformUserService.getOutPlatformUserByTempToken(OutPlatformTypeEnum.getById(platformId), sign, tempToken);
    }

}
